package com.puff.controller.user;

import com.puff.dto.ShopListDTO;
import com.puff.dto.ShopPageQueryDTO;
import com.puff.result.PageResult;
import com.puff.result.Result;
import com.puff.service.ShopService;
import com.puff.vo.ShopVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userShopController")
@RequestMapping("/user/shop")
@Api(tags = "店铺相关接口")
@Slf4j
public class ShopController {

    private static final String KEY = "SHOP_STATUS_";

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private ShopService shopService;

    /**
     * 获取店铺的营业状态
     * @return
     */
    @GetMapping("/status")
    @ApiOperation("获取店铺的营业状态")
    public Result<Integer> getStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY+"1");
        log.info("获取店铺的营业状态为:{}",status == 1 ? "营业中" : "打烊中");
        return Result.success(status);
    }

    /**
     * 用户端商家查询
     * @param shopListDTO
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "用户端商家查询")
    public Result<List<ShopVO>> page(ShopListDTO shopListDTO){
        log.info("用户端商家查询:{}",shopListDTO);
        // 由于是query查询而不是json，因此不需要加@RequestBody
        List<ShopVO> list = shopService.list(shopListDTO);
        return Result.success(list);
    }
}
